{extends file="../global.html"}
{block name=body}

 

<form class="layui-form"   method="post" onsubmit="return false" enctype="multipart/form-data" >
  <div class="layui-form-item">
    <label class="layui-form-label">轮播地址</label>
    <div class="layui-input-block">
      <input type="text" name="carousel_url" required id="test" lay-verify="required" value="{$res.carousel_url}" autocomplete="off" class="layui-input typename"><span id="span"></span>
    </div>
  </div>
    <div class="layui-form-item">
      <label class="layui-form-label">是否参与轮播</label>
      <div class="layui-input-block">
        <select name="carousel_state" lay-verify="required">
            <option value="1" {if $res.carousel_state == 1} selected{/if}>显示</option>
            <option value="0" {if $res.carousel_state == 0} selected{/if}>隐藏</option>
       </select>
      </div>
    </div>
  

  <!-- <input type="hidden" name="" value="" class=""> -->


  
</form>
<div class="layui-form-item" >
   <label class="layui-form-label" style="margin:15px">轮播图片</label>　　　　　　　　　　　　　　　　　　　　　　　　
                 
   　　　　　　　　　<div id="result" clss="website_log"><img  width="36" src="{$absroot}{$res.carousel_pic}" alt=""></div>  
                 　 <form id="form1" clss="website_log">  
                           <input type="hidden" name="carousel_id" value="{$res.carousel_id}"/>
                    　　　　　　　<input type="button" clss="carousel_pic" value="上传图片" onclick="f.click()" class="layui-btn layui-btn-normal "/><br>  
                     <p><input type="file" id="f" name="pic"  style="display:none"/></p>  
                  </form>  
  </div>
  <br/>
  <div class="layui-form-item">
    <div class="layui-input-block">
    
      <button class="layui-btn" id="btn"  lay-submit onclick="insert()" lay-filter="formDemo" >立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
<label><input type="radio" name="pinyin_type" value="1"/ checked style="display: none;"></label>
<div id="result"></div>
 




<script>
function insert(){
  // alert(1);
    var carousel_state = $("select[name=carousel_state]").val();
      var  url =   $(":text[name=carousel_url]").val();
       var  carousel_id =   $(":hidden[name=carousel_id]").val();

       sc()
      $.ajax({
          type:"post",
          data:{ carousel_state:carousel_state,carousel_url:url,carousel_id:carousel_id},
          url:"{url('run/carousel/update')}",
          success:function(msg){
            if(msg == true){
              layer.msg('修改成功');

               window.location.href="{url('/run/carousel/index')}";
            }
          
          }
      })

        
}
    
  // console.log(from);
   


   function sc(){    
        var form = $('#form1')[0];
       
     // var  carousel_id =   $(":hidden[name=carousel_id]").val();
        var data = new FormData(form);   
        // console.log(data);return;
        $.ajax({    
            url: "{url('run/carousel/pic')}",   
            type: 'POST',    
            data: data, 
            fileElementId:'f',
            dataType: 'JSON',    
            cache: true,
            processData: false,    
            contentType: false    
        }).done(function(ret){ 

          // console.log(ret);return;  
            if(ret['isSuccess'] == '图片上传过大,请重新上传'){  
                 layer.msg('上传失败,图片上传过大,请重新上传');  
            }else if(ret['isSuccess'] == '没有图片上传'){  
                  layer.msg('没有图片上传');
            }else if(ret['isSuccess'] == '只有部分文件上传'){ 
                  layer.msg('只有部分文件上传');
            }else{

               
                var result = '';  
                var result1 = '';  
                // $("#show").attr('value',+ ret['f'] +);  
                result += '<img src="{$absroot}' + ret['f']  + '" width="36">';  
                // result1 += '<input value="' + ret['f']  + '" name="user_headimg" style="display:none;">';  
                $('#result').html();  
                $('#result').html(result);  
                // $('#show').html(result1);  
                layer.msg('修改成功');  
                window.location.href="{url('/run/carousel/index')}";
            }    
        });    
        return false;    
    } 

</script>



{/block}